package com.fun_ordering.controller;

import com.fun_ordering.components.ApiResponse;
import com.fun_ordering.components.PageResult;
import com.fun_ordering.pojo.MarketingActivity;
import com.fun_ordering.service.MarketingActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 营销活动表controller
 * @author XiaoPi
 *
 */
@RestController
@RequestMapping("/marketingActivity")
public class MarketingActivityController {

	@Autowired
	private MarketingActivityService marketingActivityService;

	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findAll")
	public List<MarketingActivity> findAll(){
		return marketingActivityService.findAll();
	}


	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findPage")
	public PageResult  findPage(int page,int rows){
		return marketingActivityService.findPage(page, rows);
	}

	/**
	 * 增加
	 * @param marketingActivity
	 * @return
	 */
	@RequestMapping("/add")
	public ApiResponse add(@RequestBody MarketingActivity marketingActivity){
		try {
			marketingActivityService.add(marketingActivity);
		return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
		return ApiResponse.failed(null);
		}
	}

	/**
	 * 修改
	 * @param marketingActivity
	 * @return
	 */
	@RequestMapping("/update")
	public ApiResponse update(@RequestBody MarketingActivity marketingActivity){
		try {
			marketingActivityService.update(marketingActivity);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}

	/**
	 * 获取实体
	 * @param actId
	 * @return
	 */
	@RequestMapping("/findOne")
	public MarketingActivity findOne(Integer actId){
		return marketingActivityService.findOne(actId);
	}

	/**
	 * 批量删除
	 * @param actIds
	 * @return
	 */
	@RequestMapping("/delete")
	public ApiResponse delete(Integer [] actIds){
		try {
			marketingActivityService.delete(actIds);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}

		/**
	 * 查询+分页
	 * @param marketingActivity
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/search")
	public PageResult search(@RequestBody MarketingActivity marketingActivity, int page, int rows  ){
		return marketingActivityService.findPage(marketingActivity, page, rows);
	}

}
